home *** CD-ROM | disk | FTP | other *** search
- /*
-
- POLYTOPE OBJECT INCLUDE FILE v1.0b - main include file
- Copyright (C) 1997 Thomas Willhalm
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-
- */
-
- /*
- Declare polytope object from array of vectors stored as string
-
- Usage:
- PRE: <array> is string with comma-separated list of vectors
- with no additional blanks
- PRE: <array> contains at least 3 vectors
- POST: <polytope> contains convex hull of the given points
- SIDE: <__cur_pos>, <__old_pos>, <__x>, <__y>, <string_vector>
- <_cur_pos>, <_old_pos>, <_count>, <_end>, <_n>, <_l>, <_r>
- <_array_nmb>, <_pv1>, <_pv2>, <_pv3>, <_p1>, <_p2>, <_p3>
- altered
- INT: algo is in O(n^5)
- */
-
- // count number of points
- #declare _array_nmb=0
- #declare _cur_pos=1
- #while (_cur_pos<strlen(array))
- #if (!strcmp(substr(array,_cur_pos,1),"<"))
- #declare _array_nmb = _array_nmb + 1
- #end
- #declare _cur_pos= _cur_pos+1
- #end
-
- // declare polytope
- #declare polytope =
- intersection {
- #declare _p1 = 1
- #while (_p1<_array_nmb)
- #declare array_pos = _p1
- #include "arrayget.inc"
- #declare _pv1 = float_vector
- #declare _p2 = _p1+1
- #while (_p2<=_array_nmb)
- #declare array_pos = _p2
- #include "arrayget.inc"
- #declare _pv2 = float_vector
- #declare _p3 = _p2+1
- #while (_p3<=_array_nmb)
- #declare array_pos = _p3
- #include "arrayget.inc"
- #declare _pv3 = float_vector
- #declare _n = vcross(_pv2-_pv1,_pv3-_pv1)
- #declare _l=0
- #declare _r=0
- #declare array_pos = 1
- #while (array_pos<=_array_nmb)
- #if (array_pos!=_p1 & array_pos!=_p2 & array_pos!=_p3)
- #include "arrayget.inc"
- #if (vdot(float_vector-_pv1,_n)>0)
- #declare _l=1
- #else
- #declare _r=1
- #end
- #end
- #declare array_pos = array_pos +1
- #end
- #if (_l=0)
- plane {_n,0 translate _pv1}
- #end
- #if (_r=0)
- plane {-_n,0 translate _pv1}
- #end
- #declare _p3 = _p3 + 1
- #end
- #declare _p2 = _p2 + 1
- #end
- #declare _p1 = _p1 + 1
- #end
- }
-
-